﻿using System;
using System.Collections.Generic;

using E.Model;
using E.Enum;
using E.BLL;
using E.Web.UI.Page;

using X.Pager;
using X.Pager.List;
using X.Common;

namespace E.Web.Teacher.teacher
{
    public partial class List : TeacherBasePage
    {
        public IList<DictAreaModel> areaList = new List<DictAreaModel>();
        public IList<ShortTeacherModel> teacherList = new List<ShortTeacherModel>();
        public Dictionary<int, string> projectList;
        public int areaid = -1;
        public string name;
        public string loginid;
        public string act;
        public int pid, delflag;

        protected override void ShowPage()
        {
            //areaList = GetTeacherAreaList(teacherid);

            //if (areaList.Count == 1)
            //{
            //    areaid = areaList[0].ID;
            //}
            //else
            //{
            //    areaid = XRequest.GetInt("AreaSlt", -1);
            //}

            if (authority != EnumTeacherAuthority.Admin)
            {
                projectList = (new TeacherBLL()).GetTeacherProjectInfo(teacherid);
            }
            else
            {
                projectList = (new CourseBLL()).GetInternalProjectList();
            }

            act = XRequest.GetString("act");
            name = XRequest.GetString("NameTxt");
            loginid = XRequest.GetString("LoginIDTxt");
            pid = XRequest.GetInt("ProjectSlt", -1);
            delflag = XRequest.GetInt("DelFlagSlt", -1);

            if (ispost || act == "s")
            {
                SearchTeacherModel searchModel = new SearchTeacherModel();
                searchModel.Name = name;
                searchModel.LoginID = loginid;
                searchModel.AreaID = areaid;
                searchModel.Email = "";
                searchModel.SelfID = teacherid;
                searchModel.ProjectID = pid;
                searchModel.DelFlag = delflag;

                TeacherListModel listModel = new TeacherListModel();

                CheckPageIndexValue(XRequest.GetInt("s", 1) - 1, XRequest.GetInt("g", 0), XRequest.GetInt("z", customerPageSize));

                listModel = (new TeacherBLL()).GetTeacherListByCondition(searchModel, customerPageSize, pageIndex);
                if (listModel.TotalCount > 0)
                {
                    count = listModel.TotalCount;
                    teacherList = listModel.List;
                    PagerBase pager = new ListPager(count, pageIndex, currentPgGroup, customerPageSize, defaultPagesInGroup);

                    Dictionary<string, string> parms = new Dictionary<string, string>();
                    parms.Add("act", act);
                    parms.Add("NameTxt", name);
                    parms.Add("LoginIDTxt", loginid);
                    //parms.Add("AreaSlt", areaid.ToString());
                    parms.Add("ProjectSlt", pid.ToString());
                    mypager = pager.DrawPager("selfpager", parms);
                }
            }
            
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
